﻿@Html.DevExpress().GridView(
            settings =>
            {
                settings.Name = "gvEditing";
                settings.KeyFieldName = "FDocId";
                settings.CallbackRouteValues = new { Controller = "Album", Action = "PicListPartial" };
                settings.Width =System.Web.UI.WebControls.Unit.Percentage(100);                            


                settings.SettingsBehavior.AllowSort = false;
                settings.SettingsBehavior.AllowDragDrop = false;
                settings.SettingsBehavior.AllowSelectByRowClick = false;
                settings.SettingsLoadingPanel.Text = "数据读取中...";
                settings.SettingsBehavior.AllowClientEventsOnLoad = false;
                settings.SettingsBehavior.AllowFocusedRow = false;


                settings.ClientSideEvents.BeginCallback = "function(s,e){OnBeginCallback(s,e)}";
                               

                settings.SettingsPager.Position = System.Web.UI.WebControls.PagerPosition.Bottom;
                settings.SettingsPager.FirstPageButton.Visible = true;
                settings.SettingsPager.LastPageButton.Visible = true;
                settings.SettingsPager.PageSize = ViewData["pageRowSize"] != null ? int.Parse(ViewData["pageRowSize"].ToString()) : 0;
                settings.SettingsPager.AlwaysShowPager = true;

                settings.CommandColumn.Visible = true;
                //settings.CommandColumn.ShowSelectCheckbox = true;
                settings.CommandColumn.Width = System.Web.UI.WebControls.Unit.Pixel(100);
                settings.CommandColumn.SetHeaderTemplateContent(c =>
                {
                    Html.DevExpress().CheckBox(settingsCheckBox =>
                    {
                        settingsCheckBox.Name = "cbSelectAll";
                        settingsCheckBox.Properties.ClientSideEvents.CheckedChanged = "function(s, e) {selectAll(s,e);}";

                    }).Render();

                    ViewContext.Writer.Write("相册照片");
                    
                    
                });

                               

                
                int begin = 0;
                int step = 3;
                int end = begin + step;
                List<ElingOA6_Admin_DSJCJ.Model.AlbumEntry> entryList = (List<ElingOA6_Admin_DSJCJ.Model.AlbumEntry>)Model;
                entryList = entryList.Where(c => null != c).ToList();
                int count = entryList.Count;
                if (count<end)
                {
                    end = count;
                }
               
                
                settings.SetDataRowTemplateContent(c =>
                {
                    if (begin<count)
                    {
                        ViewContext.Writer.Write(
                        "<div style=\"padding:5px\">" +
                            "<table class=\"templateTable\">" +
                                "<tr>"
                            );

                        for (int i = begin; i < end; i++)
                        {
                            ElingOA6_Admin_DSJCJ.Model.AlbumEntry entry = entryList[i];
                            
                            ViewContext.Writer.Write(
                                "<td><table>" +
                                "<tr><td rowSpan='2'>" +
                                "<img src='" + Url.Content(entry.FAlbumThumbURL) + "' width='100' height='60' onclick=\"javascript:window.open( rootPath +'/Admin/Album/PicShow?albumId=" + entry.FAlbumId + "&entryID=" + entry.FAlbumEntryID + "','picShow')\" style='cursor:pointer' />" +
                                "</td>" +
                                "<td width='200'>" +
                                entry.FAlbumNote +
                                "</td></tr><tr><td>"
                             );


                            @Html.DevExpress().CheckBox(chk =>
                            {
                                chk.Name = "chk_" + entry.FAlbumEntryID + "_*";
                            }).Render();
                            ViewContext.Writer.Write("<span onclick=\"edit('" + entry.FAlbumEntryID + "')\" style='cursor:pointer'>[编辑]</span> <span onclick=\"del('" + entry.FAlbumEntryID + "')\" style='cursor:pointer;color:red'>[删除]</span>");


                            ViewContext.Writer.Write("</td></tr></table></td>");
                        }

                        ViewContext.Writer.Write(
                            "</tr></table></div>"
                       );

                        begin = end;
                        end = begin + step;
                        if (end>count)
                        {
                            end = count;
                        }                       
                        
                    }

                });
      
                
                settings.PageIndexChanged = (sender, e) =>
                {
                    ASPxGridView grid = (ASPxGridView)sender;
                    grid.Selection.UnselectAll();
                };

                settings.DataBound = (sender, e) =>
                {
                    ASPxGridView grid = (ASPxGridView)sender;
                    if (ViewData["pageIndex"] != null)
                    {
                        if (ViewData["pageIndex"].ToString() != "")
                        {
                            if (grid.PageCount < int.Parse(ViewData["pageIndex"].ToString()))
                            {
                                grid.PageIndex = 0;
                            }
                            else
                            {
                                grid.PageIndex = int.Parse(ViewData["pageIndex"].ToString());
                            }
                        }
                    }
                };
                
                
            }).Bind(Model).GetHtml()